package com.imooc.api;

import com.imooc.api.intercept.JWTCurrentUserInterceptor;
import com.imooc.api.intercept.SMSInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public SMSInterceptor smsInterceptor(){
        return new SMSInterceptor();
    }
    @Bean
    public JWTCurrentUserInterceptor jwtCurrentUserInterceptor(){
        return new JWTCurrentUserInterceptor();
    }

    /**
     *注册拦截器并且指定拦截的路由
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(smsInterceptor()).addPathPatterns("/passport/getSMSCode");
        registry.addInterceptor(jwtCurrentUserInterceptor()).addPathPatterns("/**");
    }
}
